package com.cdut.config;

import com.cdut.interceptor.RememberMeInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

//        registry.addResourceHandler("/updatafile/**").addResourceLocations("file:/home/lighthouse/myapp/updatafile/");

        registry.addResourceHandler("/updatafile/**").addResourceLocations("file:/home/xinmu/code/mall/target/updatefile/");

    }
    //视图跳转
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("home");
        registry.addViewController("/home").setViewName("home");
        registry.addViewController("/about").setViewName("about");
        registry.addViewController("/productdetails-fullwidth").setViewName("productdetails-fullwidth");
        registry.addViewController("/checkout").setViewName("checkout");
        registry.addViewController("/gridproducts_bannerslider").setViewName("gridproducts_bannerslider");
        registry.addViewController("/gridproducts_bannerslider2").setViewName("gridproducts_bannerslider2");
        registry.addViewController("/gridproducts_bannerslider_my").setViewName("gridproducts_bannerslider_my");
        registry.addViewController("/shoppingcart").setViewName("shoppingcart");
        registry.addViewController("/404page").setViewName("404page");
        registry.addViewController("/login").setViewName("login");
    }


    //配置将通过记住我登录的用户对象放入session中的拦截器
    @Autowired
    RememberMeInterceptor rememberMeInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(rememberMeInterceptor).addPathPatterns("/**").
                excludePathPatterns("/toLogin","/error");
    }
}